﻿using BCCommon.TMS.FreightEnums;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.FreightContact;
using BCService.TMS.FreightContactService;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.ClientApp.Freight
{
    /// <summary>
    /// 常用联系人
    /// </summary>
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [Route("api/v1/ClientApp/[controller]")]
    public class FreightContactController : ClientAppBaseController
    {
        private readonly IFreightContactService freightContactService;

        public FreightContactController(IFreightContactService freightContactService)
        {
            this.freightContactService = freightContactService;
        }

        #region 添加常用联系人
        /// <summary>
        /// 添加常用联系人
        /// </summary>
        /// <param name="freightContactRequestDto">常用联系人信息</param>
        /// <response code="201">常用联系人信息</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加常用联系人")]
        [ProducesResponseType(typeof(FreightContactDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Post([FromBody] FreightContactRequestDto freightContactRequestDto)
        {
            return Created("api/v1/ClientApp/FreightContact/{0}", this.freightContactService.Add(this.UserInfo, freightContactRequestDto));
        }
        #endregion

        #region 修改常用联系人
        /// <summary>
        /// 修改常用联系人
        /// </summary>
        /// <param name="freightContactId">常用联系人Id</param>
        /// <param name="freightContactRequestDto">常用联系人信息</param>
        /// <response code="200">常用联系人信息</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{freight_contact_id}")]
        [Log("修改常用联系人")]
        [ProducesResponseType(typeof(FreightContactDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromRoute(Name = "freight_contact_id")] long freightContactId, [FromBody] FreightContactRequestDto freightContactRequestDto)
        {
            return Ok(this.freightContactService.Update(this.UserInfo, freightContactId, freightContactRequestDto));
        }
        #endregion

        #region 删除常用联系人
        /// <summary>
        /// 删除常用联系人
        /// </summary>
        /// <param name="freightContactId">常用联系人Id</param>
        /// <response code="204">NoContent</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{freight_contact_id}")]
        [Log("删除常用联系人")]
        [ProducesResponseType(typeof(OkObjectResult), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Delete([FromRoute(Name = "freight_contact_id")] long freightContactId)
        {
            this.freightContactService.Delete(this.UserInfo, freightContactId);
            return Ok();
        }
        #endregion

        #region 获取常用联系人
        /// <summary>
        /// 获取常用联系人
        /// </summary>
        /// <param name="freightContactType">常用联系人类型</param>
        /// <response code="200">常用联系人列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(FreightContactDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Get([FromQuery(Name = "freight_contact_type")] FreightContactType? freightContactType)
        {
            return Ok(this.freightContactService.Get(this.UserInfo.UserId, freightContactType));
        }
        #endregion
    }
}
